package com.haidong.listener;

import com.haidong.Manager;
import com.haidong.component.AdminIndexFrame;
import com.haidong.component.LoginFrame;
import com.haidong.component.UserIndexFrame;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 监听登录界面的登录按钮并处理
 */
public class MyButtonActionListener implements ActionListener {
    TextField id,psw;
    LoginFrame frame;
    boolean isAdmin;
    public MyButtonActionListener(LoginFrame frame,TextField id, TextField psw,boolean isAdmin) {
        this.id = id;
        this.psw = psw;
        this.frame = frame;
        this.isAdmin = isAdmin;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        //调用静态的密码校验函数
        try {
            String userName = id.getText();
            int[] judgeAndId = Manager.judgeUser(userName, psw.getText());
            int judge = judgeAndId[0],userId = judgeAndId[1];
            if(judge==1){
                frame.dispose();
                new AdminIndexFrame("管理员窗口",userId,userName);
            }else if(judge==2){
                frame.dispose();
                System.out.println("期望");
                new UserIndexFrame("普通窗口",userId,userName);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
